package com.budwk.app.sqfw.enums;

import com.budwk.app.sqfw.constants.CommonConstants;
import com.budwk.app.sys.models.Sys_user;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * 文件聚合bean枚举
 *
 * @author zhangp
 * @date 2024-05-09
 */
@Getter
public enum FileMergingBeanNameEnum {

    BaiYunQu12345AuthForAdminService("BaiYunQu12345AuthForAdminService", "白云区12345确权", "12345确权", "白云区"),
    BaiYunQuChildVisitForAdminService("BaiYunQuChildVisitForAdminService", "白云区儿童探访", "儿童探访记录", "白云区"),
    BaiYunQuSpecOldManVisitForAdminService("BaiYunQuSpecOldManVisitForAdminService", "白云区特殊老年人探访", "特殊老年人探访", "白云区"),
    CenturyCityCareStaffForAdminService("CenturyCityCareStaffForAdminService", "世纪城街道党员关爱走访", "关爱人员探访", "世纪城街道"),
    CenturyCityForbidDrugForAdminServic("CenturyCityForbidDrugForAdminService", "世纪城街道禁毒宣传/排查", "宣传/排查记录", "世纪城街道"),
    DuLaYingProChkForAdminService("DuLaYingProChkForAdminService", "都拉营宣传排查", "宣传/排查记录", "都拉营街道"),
    CenturyCityPatrolForAdminService("CenturyCityPatrolForAdminService", "世纪城林河汛灾防治", "林河汛灾防治", "世纪城街道"),
    DaYingLuSocietySecForAdminService("DaYingLuSocietySecForAdminService", "社会治安", "社会治安", "贵阳市"),
    GuanShanHuEntGuaranteeForAdminService("GuanShanHuEntGuaranteeForAdminService", "观山湖区企业包保服务", "企业包保服务", "观山湖区"),
    GuanShanHuJCERegistForAdminService("GuanShanHuJCERegistForAdminService", "观山湖区创业实体入户", "创业实体入户", "观山湖区"),
    GuanShanHuNonSchoolSysForAdminService("GuanShanHuNonSchoolSysForAdminService", "观山湖非学制教育机构巡查", "非学制教育机构巡查", "观山湖区"),
    ShaWenZhenSecurityForAdminService("ShaWenZhenSecurityForAdminService", "沙文镇安全排查", "安全排查", "沙文镇"),
    CenturyCitySecurityForAdminService("CenturyCitySecurityForAdminService", "世纪城安全排查", "安全排查", "观山湖区"),
    //CenturyCitySecurityForAdminService("CenturyCitySecurityForAdminService", "世纪城安全排查服务", "安全排查", "世纪城街道|观山街道|宾阳街道"),
    DaYingLuSecurityForAdminService("DaYingLuSecurityForAdminService", "大营路安全排查服务", "安全排查", "大营路街道"),
    DaYingLuRedWhiteRecordForAdminService("DaYingLuRedWhiteRecordForAdminService", "大营路街道红白事备案", "红白事备案", "大营路街道"),
    SqfwCustomForAdminCommonService("SqfwCustomForAdminCommonService", "世纪城街道养老服务巡查", "养老服务站巡查", "世纪城街道"),
    ;

    private final String beanName;//注入的bean名称

    private final String name;//服务名称

    private final String type;//任务类型

    private final String tag;//适用范围标签，多个用|隔开，如：世纪城街道|观山街道|宾阳街道

    FileMergingBeanNameEnum(String beanName, String name, String type, String tag) {
        this.beanName = beanName;
        this.name = name;
        this.type = type;
        this.tag = tag;
    }


    public static FileMergingBeanNameEnum getServiceTypeByName(String name) {
        for (FileMergingBeanNameEnum o : FileMergingBeanNameEnum.values()) {
            if (o.getName().contains(name)) {
                return o;
            }
        }
        return null;
    }

    public static FileMergingBeanNameEnum getServiceByType(String type, Sys_user user) {
        FileMergingBeanNameEnum fileMergingBeanNameEnum = null;
        List<String> tags = new ArrayList<>();
        if (!CommonConstants.DIRECTLY_UNDER.equals(user.getCommunity())) {
            tags.add(user.getCommunity());
        }
        if (!CommonConstants.DIRECTLY_UNDER.equals(user.getCounty())) {
            tags.add(user.getCounty());
        }
        if (!CommonConstants.DIRECTLY_UNDER.equals(user.getDistrict())) {
            tags.add(user.getDistrict());
        }
        if (!CommonConstants.DIRECTLY_UNDER.equals(user.getCity())) {
            tags.add(user.getCity());
        }
        if (!CommonConstants.DIRECTLY_UNDER.equals(user.getProvince())) {
            tags.add(user.getProvince());
        }
        List<FileMergingBeanNameEnum> fileMergingBeanNameEnums = new ArrayList<>();
        for (FileMergingBeanNameEnum o : FileMergingBeanNameEnum.values()) {
            if (o.getType().equals(type)) {
                fileMergingBeanNameEnums.add(o);
            }
        }
        //根据类型去取值如果只有一个那么直接取不比较tag五级范围，如果有多个则需要比较范围
        if (fileMergingBeanNameEnums.size() == 1) return fileMergingBeanNameEnums.get(0);
        for (String tag : tags) {
            for (FileMergingBeanNameEnum o : fileMergingBeanNameEnums) {
                if (o.getTag().contains(tag)) {
                    fileMergingBeanNameEnum = o;
                    break;
                }
            }
        }
        return fileMergingBeanNameEnum;
    }


}
